
public class HMMNode {
	final int MaxMatchLen=20;
	final int MaxInsertLen=20;
	final int MaxDeleteLen=7;
	private double[] MatchProbability=new double[MaxMatchLen];
	private double[] InsertProbability=new double[MaxInsertLen];
	private double TranProbability[]=new double[MaxDeleteLen];

	public HMMNode(String ss){
		SetProbability(ss);
	}
	
	public HMMNode(){}
	

	//Get Match state probability
	public double GetMatchProbability(int pos){
		if (pos < MaxMatchLen){
			return MatchProbability[pos];
		}
		else {
			return 0;
		}
			
	}
	
	//Get Insert state probability
	public double GetInsertProbability(int pos){
		if (pos < MaxInsertLen){
			return InsertProbability[pos];
		}
		else {
			return 0;
		}
		
	}
	
	//Get transition state probability
	public double GetTranProbability(int pos){
		if (pos < MaxDeleteLen){
			return TranProbability[pos];
		}
		else {
			return 0;
		}
	}
	
	//set the probability of one component in HMMER profile
	public boolean SetProbability(String ss){

		String[] line = ss.split("\r");
		if (line.length<3)
			return false;
		String[] Possibility0 = line[0].split(" ");
		
		
		
		//set match state probability
		for (int i = 0,j=0; j < MaxMatchLen && i < Possibility0.length; i++) {

			try {
				while (Possibility0[i].equals("")) {
					i++;
				}
				MatchProbability[j] = Double.parseDouble(Possibility0[i]);
				j++;
			} catch (NumberFormatException ex) {
				//ex.printStackTrace();

			}

		}
		
		//set insert state probability
		String[] Possibility1 = line[1].split(" ");
		for (int i = 0, j=0; j < MaxInsertLen && i< Possibility1.length; i++) {
		
			try {
				while (Possibility1[i].equals("")) {
					i++;
				}
				InsertProbability[j] = Double.parseDouble(Possibility1[i]);
				j++;
			} catch (NumberFormatException ex) {
				//ex.printStackTrace();

			}
			
		}
		
		//set delete state probability
		String[] Possibility2 = line[2].split(" ");
		for (int i = 0, j=0; j < MaxDeleteLen && i< Possibility2.length; i++) {
		
			try {
				while (Possibility2[i].equals("")) {
					i++;
				}
				TranProbability[j] = Double.parseDouble(Possibility2[i]);
				j++;
			} catch (NumberFormatException ex) {
				//ex.printStackTrace();

			}
			
		}

		return true;
	}
	
	/*
	public static void main (String[] args){
		
		double M_double,I_double,T_double;
		HMMNode HMMnode= new HMMNode();
		String s = "COMPO   2.27165  4.34062  2.74969  2.66237  3.85083  2.68422  3.94348  3.25360  2.57389  2.81374  4.07419  3.19305  2.51331  2.98243  3.36374  2.95177  2.70552  2.63822  3.56042  3.77216 \r  2.68618  4.42225  2.77519  2.73123  3.46354  2.40513  3.72494  3.29354  2.67741  2.69355  4.24690  2.90347  2.73739  3.18146  2.89801  2.37887  2.77519  2.98518  4.58477  3.61503 0.0015 \r 6.88065  7.60300  0.61958  0.77255  0.00000        *";
		HMMnode.SetProbability(s);
		M_double=HMMnode.GetMatchProbability(5);
		T_double=HMMnode.GetTranProbability(5);
		I_double=HMMnode.GetInsertProbability(18);
		
		System.out.printf("M_double：%f \r",M_double);
		System.out.printf("I_double：%f \r",I_double);
		System.out.printf("T_double：%f \r",T_double);
	}
	*/
}
